Extended product with additional functionalities#172
Merged
Conversation
Reviewer's GuideThis PR enriches the Product model with context-aware async methods by capturing the client in a private attribute, updates client methods to use pydantic’s model_validate with context, improves timezone handling in transaction requests, extends rating field validation, and adds an integration test for the new Product functionality. Class diagram for updated Product model and ProductsClientclassDiagram
class Product {
+str symbol
+str name
+str description
+str exchange
+str currency
+str isin
+str type
+str sector
+str industry
+str country
+str logo_url
+datetime inception_date
+List instrument_tags
+List child_instruments
-StakeClient _client
+model_post_init(context)
+ratings() async
+statements(start_date=None) async
}
class ProductsClient {
+get(symbol) async Product|None
+search(request) async List[Instrument]
+product_from_instrument(instrument) async Product|None
}
Product <.. ProductsClient : used by
ProductsClient o-- Product : returns
Product o-- "1" StakeClient : _client
Product o-- "*" Rating : ratings()
Product o-- "*" Statement : statements()
Class diagram for updated TransactionRecordRequestclassDiagram
class TransactionRecordRequest {
+datetime to
+datetime from_
+int limit
+datetime|None offset
}
Class diagram for updated Rating field validationclassDiagram
class Rating {
+str|None pt_prior
+str|None rating_prior
+str|None pt_current
+str|None rating_current
+pt_prior_blank_string(value, *args) classmethod
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @stabacco - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `stake/product.py:65` </location>
<code_context>
+ _client: "StakeClient" = PrivateAttr()
model_config = ConfigDict(alias_generator=camelcase)
+ def model_post_init(self, context: Any) -> None:
+ self._client = context.get("client")
+
+ async def ratings(self) -> "List[Rating]":
</code_context>
<issue_to_address>
No fallback if 'client' is missing from context in model_post_init.
Setting self._client to None may cause runtime errors if 'client' is missing. Raise an explicit error or provide a fallback to handle this case predictably.
</issue_to_address>
### Comment 2
<location> `stake/transaction.py:21` </location>
<code_context>
class TransactionRecordRequest(BaseModel):
- to: datetime = Field(default_factory=datetime.utcnow)
+ to: datetime = Field(default_factory=lambda *_: datetime.now(UTC))
from_: datetime = Field(
- default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from"
</code_context>
<issue_to_address>
Switch to timezone-aware datetime is an improvement, but UTC must be defined.
Verify that 'UTC' is properly imported to avoid a NameError at runtime.
</issue_to_address>
### Comment 3
<location> `stake/transaction.py:23` </location>
<code_context>
- to: datetime = Field(default_factory=datetime.utcnow)
+ to: datetime = Field(default_factory=lambda *_: datetime.now(UTC))
from_: datetime = Field(
- default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from"
+ default_factory=lambda *_: datetime.now(UTC) - timedelta(days=365), alias="from"
)
limit: int = 1000
</code_context>
<issue_to_address>
Same UTC concern applies to from_ default_factory.
Ensure that UTC is properly defined and accessible in this context.
</issue_to_address>
### Comment 4
<location> `stake/ratings.py:39` </location>
<code_context>
url_news: Optional[str] = None
analyst_name: Optional[str] = None
- @pydantic.field_validator("pt_prior", "rating_prior", mode="before")
+ @pydantic.field_validator("pt_prior", "rating_prior", "pt_current", "rating_current", mode="before")
@classmethod
def pt_prior_blank_string(cls, value, *args) -> Optional[str]:
</code_context>
<issue_to_address>
Validator now applies to more fields, but function name is misleading.
Consider renaming pt_prior_blank_string to better reflect that it now validates multiple fields.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| to: datetime = Field(default_factory=datetime.utcnow) | ||
| to: datetime = Field(default_factory=lambda *_: datetime.now(UTC)) | ||
| from_: datetime = Field( | ||
| default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from" |
There was a problem hiding this comment.
issue (bug_risk): Same UTC concern applies to from_ default_factory.
Ensure that UTC is properly defined and accessible in this context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Add ratings and statements endpoints to Product model, ensure Pydantic models receive client context, update default datetime handling, extend ratings validator, and include integration tests for product features
New Features:
Bug Fixes:
Enhancements:
Tests: